package com.lxb.myforum.service.spec

import java.util.ArrayList

import javax.persistence.criteria.CriteriaBuilder
import javax.persistence.criteria.CriteriaQuery
import javax.persistence.criteria.Predicate
import javax.persistence.criteria.Root

import org.springframework.data.jpa.domain.Specification

import com.lxb.myforum.pojo.Menu

class MenuSpec(private val menu: Menu) : Specification<Menu> {

    override fun toPredicate(root: Root<Menu>, query: CriteriaQuery<*>, cb: CriteriaBuilder): Predicate? {
        val predicates = ArrayList<Predicate>()
        if (menu.parentId!! >= 0) {
            predicates.add(cb.equal(root.get<Any>("parentId"), menu.parentId))
        }
        query.where(*predicates.toTypedArray())
        return null
    }
}
